# Replication Archive for: 
# Coppock, Alexander and Donald P. Green. 2020. 
# "Do Belief Systems Exhibit Dynamic Constraint?" 
# The Journal of Politics, Forthcoming.

rm(list = ls())

library(tidyverse)
library(estimatr)
library(stargazer)

source("programs/helpers/helper_functions.R")

study_2 <- read_rds("data/clean/study_2_lucid_clean.rds")
study_2_replication <- read_rds("data/clean/studies_1_2_replications_lucid_cleaned.rds")

corr_mat <- 
study_2_replication %>%
  select(gays_employers,
         ssm_exempt,
         ssm_ammend,
         prayer_football,
         prayer_ammend) %>%
  cor(use = "complete.obs")

diag(corr_mat) <- NA

max(corr_mat, na.rm = TRUE)
min(corr_mat, na.rm = TRUE)


fit_1 <- lm(gays_employers ~ Z_gays, data = study_2)
fit_2 <- lm(ssm_exempt ~ Z_gays, data = study_2)
fit_3 <- lm(ssm_ammend ~ Z_gays, data = study_2)
fit_4 <- lm(prayer_football ~ Z_gays, data = study_2)
fit_5 <- lm(prayer_ammend ~ Z_gays, data = study_2)

stargazer(fit_1, fit_2, fit_3, fit_4, fit_5,
          p = starprep(fit_1, fit_2, fit_3, fit_4, fit_5, stat = "p.value"),
          se = starprep(fit_1, fit_2, fit_3, fit_4, fit_5),
          dep.var.labels = c("Employers", "Local Officials", "SSM Amend", "Prayer", "Prayer Amend"),
          covariate.labels = c("Religious Exemption", "Constant (Control Mean)"),
          column.labels = c("Manip. Q.", "Outcomes"),
          column.separate = c(1, 4),
          style = "apsr",
          column.sep.width = "0pt",
          omit.stat = c("f", "ser", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05),
          label = "tab:ssm",
          notes = c("Robust standard errors are in parentheses."),
          font.size = "footnotesize",
          title = "Employment Discrimination Experimental Results",
          out = "../Drafts/tables/study_2_ssm.tex")


fit_1 <- lm(gays_employers ~ Z_gays, data = study_2_replication)
fit_2 <- lm(ssm_exempt ~ Z_gays, data = study_2_replication)
fit_3 <- lm(ssm_ammend ~ Z_gays, data = study_2_replication)
fit_4 <- lm(prayer_football ~ Z_gays, data = study_2_replication)
fit_5 <- lm(prayer_ammend ~ Z_gays, data = study_2_replication)

stargazer(fit_1, fit_2, fit_3, fit_4, fit_5,
          p = starprep(fit_1, fit_2, fit_3, fit_4, fit_5, stat = "p.value"),
          se = starprep(fit_1, fit_2, fit_3, fit_4, fit_5),
          dep.var.labels = c("Employers", "Local Officials", "SSM Amend", "Prayer", "Prayer Amend"),
          covariate.labels = c("Religious Exemption", "Constant (Control Mean)"),
          column.labels = c("Manip. Q.", "Outcomes"),
          column.separate = c(1, 4),
          style = "apsr",
          column.sep.width = "0pt",
          omit.stat = c("f", "ser", "rsq", "adj.rsq"),
          star.cutoffs = c(0.05),
          label = "tab:ssm",
          notes = c("Robust standard errors are in parentheses."),
          font.size = "footnotesize",
          title = "Lucid Replication: Employment Discrimination Experimental Results",
          out = "../Drafts/tables/study_2_replication_ssm.tex")

